//
//  AppDelegate.m
//  Shangshu
//
//  Created by MingmingSun on 2017/10/12.
//  Copyright © 2017年 Sunmingming. All rights reserved.
//

#import "AppDelegate.h"
#import "tooles.h"
#import <MMDrawerController.h>
#import <MMDrawerVisualState.h>
#import "MMExampleLeftSideDrawerViewController.h"
#import "StartViewController.h"
#import "SMMNavigationController.h"
#import <LKDBHelper.h>
@interface AppDelegate ()

@property(nonatomic,strong) MMDrawerController *cacheDrawer;
@property(nonatomic,strong) MMExampleLeftSideDrawerViewController *leftDrawer;

@end

@implementation AppDelegate

@synthesize cacheDrawer;
@synthesize window = _window;

#pragma mark UIApplicationDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.globalSoundManager = [AFSoundManager sharedManager];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.mainBookArray = [YJBookItem searchWithWhere:@"AllowPlayAudio>0" orderBy:@"Page" offset:0 count:200];
    self.nowLevel = [tooles getPlistValueForKey:@"level"];
    self.globalItem = [APPALL.mainBookArray objectAtIndex:(self.nowLevel-1)];
    // Custom initialization
    NSLog(@"array count: %d",self.mainBookArray.count);
    
    //    NSLog(@"fffff:%d",self.nowLevel);
    self.cacheDrawer = [[MMDrawerController alloc] init];
    self.leftDrawer = [[MMExampleLeftSideDrawerViewController alloc] init];
    [cacheDrawer setLeftDrawerViewController:self.leftDrawer];
    [cacheDrawer setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
    [cacheDrawer setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    [cacheDrawer setDrawerVisualStateBlock:[MMDrawerVisualState slideAndScaleVisualStateBlock]];
    [cacheDrawer setCenterHiddenInteractionMode:MMDrawerOpenCenterInteractionModeNavigationBarOnly];
    [cacheDrawer openDrawerSide:MMDrawerSideLeft animated:NO completion:nil];
    self.window.rootViewController = cacheDrawer;
    [self.window makeKeyAndVisible];
    
    StartViewController *loginVC = [[StartViewController alloc] init];
    SMMNavigationController *nav = [[SMMNavigationController alloc] initWithRootViewController:loginVC];
    [self.window.rootViewController presentViewController:nav animated:NO completion:nil];
    
    return YES;
}

- (BOOL)shouldAutorotate
{
    return YES;
}

-(void)startWithDrawerIndex:(int)aIndex
{
    [self.leftDrawer drawChanged:aIndex];
}

@end
